from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
#实例化浏览器
driver = webdriver.Chrome()
action = ActionChains(driver)
#打开网页
driver.get('file:///E:/%E5%AD%A6%E4%B9%A0%E7%B4%A0%E6%9D%90/%E9%98%B6%E6%AE%B5%E4%B8%83%EF%BC%9A%20Web%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/%E8%AF%BE%E5%A0%82%E7%B4%A0%E6%9D%90/%E6%B3%A8%E5%86%8C%E5%AE%9E%E4%BE%8B/%E6%B3%A8%E5%86%8CA.html')
#点击点击 alert按钮
driver.find_element_by_id('alerta').click()
#获取alert提示文本信息
print(driver.switch_to.alert.text)
#点击对话框中的同意
driver.switch_to.alert.accept()

#鼠标操作 注册A页面 账号A输入admin 双击 admin为选中状态 效果如下
driver.find_element_by_id('userA').send_keys('admin')
action.double_click(driver.find_element_by_id('userA')).perform()

#移动到注册按钮上 预期：按钮变色
move = driver.find_element_by_xpath('/html/body/form/div/fieldset/button')
action.move_to_element(move).perform()

"""
三、frame 切换 - 填写用户名 密码 电话 邮件信息

1. 打开注册实例.html 

2. 填写主页面 页面信息 

3. 填写注册A 页面信息 

4、切换到默认目录 driver.switch_to.default_content() 

5. 填写注册B 页面信息
"""
#1. 打开注册实例.html
driver.get('file:///E:/%E5%AD%A6%E4%B9%A0%E7%B4%A0%E6%9D%90/%E9%98%B6%E6%AE%B5%E4%B8%83%EF%BC%9A%20Web%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/%E8%AF%BE%E5%A0%82%E7%B4%A0%E6%9D%90/%E6%B3%A8%E5%86%8C%E5%AE%9E%E4%BE%8B/%E6%B3%A8%E5%86%8C%E5%AE%9E%E4%BE%8B.html')
#2. 填写主页面 页面信息
driver.find_element_by_id('user').send_keys('admin')
driver.find_element_by_id('password').send_keys('123456')
driver.find_element_by_id('tel').send_keys('13800138001')
driver.find_element_by_id('email').send_keys('123@qq.com')
#3. 填写注册A 页面信息
idframe1 = driver.find_element_by_id('idframe1')
driver.switch_to.frame(idframe1)
driver.find_element_by_id('userA').send_keys('adminA')
driver.find_element_by_id('passwordA').send_keys('123456A')
driver.find_element_by_id('telA').send_keys('13800138002')
driver.find_element_by_id('emailA').send_keys('456@qq.com')
#4、切换到默认目录 driver.switch_to.default_content()
driver.switch_to.default_content()
#5. 填写注册B 页面信息
myframe2 = driver.find_element_by_xpath('/html/body/s/iframe[2]')
driver.switch_to.frame(myframe2)
driver.find_element_by_id('userB').send_keys('adminB')
driver.find_element_by_id('passwordB').send_keys('123456B')
driver.find_element_by_id('telB').send_keys('13800138003')
driver.find_element_by_id('emailB').send_keys('789@qq.com')


